package dao;

import java.util.ArrayList;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import beans.Section;

public class SectionDao {

	private EntityManagerFactory emf = Persistence
			.createEntityManagerFactory("connection");
	private EntityManager em = emf.createEntityManager();

	public SectionDao() {

	}

	@SuppressWarnings("unchecked")
	public ArrayList<Section> getAllSections() {
		return (ArrayList<Section>) em.createQuery(
				"SELECT Section FROM Section Section").getResultList();
	}

	public Section getSectionById(int id) {
		return (Section) em.createQuery(
				"SELECt Section FROM Section Section WHERE Section.id=" + id)
				.getSingleResult();
	}
}
